package com.ibm.rules;

public enum RuleMode {
	EMIT_WHEN_HIT(
			new EmitTester() {
				
				@Override
				public boolean shouldEmit(Boolean previousState, Boolean currentState) {
					return currentState;
				}
			}
			),
	EMIT_WHEN_BECOME_HIT(
			new EmitTester(){

				@Override
				public boolean shouldEmit(Boolean previousState, Boolean currentState) {
					return !previousState && currentState;
				}
				
			}
			),
	EMIT_WHEN_BECOME_UNHIT(
			new EmitTester(){

				@Override
				public boolean shouldEmit(Boolean previousState, Boolean currentState) {
					return previousState && !currentState;
				}
				
			}
			),
	EMIT_WHEN_STATE_CHANGE(
			new EmitTester(){

				@Override
				public boolean shouldEmit(Boolean previousState, Boolean currentState) {
					return previousState != currentState;
				}
				
			}
			),
	EMIT_WHEN_STATE_CHANGE_OR_HIT(
			new EmitTester(){

				@Override
				public boolean shouldEmit(Boolean previousState, Boolean currentState) {
					return currentState || (previousState != currentState);
				}
				
			}
			);
	
	private final EmitTester tester;
	
	private RuleMode(EmitTester tester){
		this.tester = tester;
	}
	
	public boolean shouldEmit(Boolean previousState, Boolean currentState){
		return tester.shouldEmit(previousState, currentState);
	}
	
	private interface EmitTester{
		public boolean shouldEmit(Boolean previousState, Boolean currentState);
	}
}
